package com.sneakxy.mybase4j.platform.beans;

import java.util.Calendar;
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.data.annotation.Id;
import org.springframework.web.multipart.MultipartFile;

import com.sneakxy.mybase4j.base.bean.BaseEntity;
import com.sneakxy.mybatis.commons.annotations.Column;
import com.sneakxy.mybatis.commons.annotations.Table;
import com.sneakxy.mybatis.commons.orm.generation.GeneratedValue;
import com.sneakxy.mybatis.commons.orm.generation.GenerationType;

/**
 * 
 * @author 潜行的青衣
 * @see
 */
@Table("t_mb4j_ueditor")
public class UEditor extends BaseEntity<String> {

	private final static long serialVersionUID = -1L;

	public final static String TYPE_IMAGE = "image";
	
	public final static String TYPE_VIDEO = "video";
	
	public final static String TYPE_FILE = "file";
	
	public final static String STORAGE_FASTDFS = "fastdfs";
	
	public final static String STORAGE_FTP = "ftp";
	
	public final static String STORAGE_LOCAL = "local";
	
	@Id
	@Column("id")
	@GeneratedValue(strategy = GenerationType.UUID)
	private String id;
	
	@Column("account")
	private String account;
	
	@Column("filename")
	private String filename;

	@Column("filepath")
	private String filepath;

	@Column("type")
	private String type;

	@Column("storage")
	private String storage;

	@Column("content_type")
	private String contentType;

	@Column("content_size")
	private Long contentSize;

	@Column("createtime")
	private String createtime;

	public Map<String, Object> toMap() {
		Map<String, Object> result = new LinkedHashMap<String, Object>();
		result.put("state", "SUCCESS");
		result.put("url", this.getId());
		result.put("title", this.getFilename());
		result.put("original", this.getFilename());
		return result;
	}
	
	public static UEditor newInstance(MultipartFile file) {
		UEditor ueditor = new UEditor();
		ueditor.setFilename(file.getOriginalFilename());
		ueditor.setCreatetime(DateFormatUtils.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss"));
		ueditor.setContentType(file.getContentType());
		ueditor.setContentSize(file.getSize());
		return ueditor;
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public String getFilepath() {
		return filepath;
	}

	public void setFilepath(String filepath) {
		this.filepath = filepath;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getStorage() {
		return storage;
	}

	public void setStorage(String storage) {
		this.storage = storage;
	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public Long getContentSize() {
		return contentSize;
	}

	public void setContentSize(Long contentSize) {
		this.contentSize = contentSize;
	}

	public String getCreatetime() {
		return createtime;
	}

	public void setCreatetime(String createtime) {
		this.createtime = createtime;
	}

}
